package com.java2007.hotel.dao.impl;

import com.java2007.hotel.dao.AdminDao;
import com.java2007.hotel.pojo.Admin;
import com.java2007.hotel.utils.JdbcUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author ghy
 * @version 1.0
 * @date 2021-01-25
 */
public class AdminDaoImpl implements AdminDao {
    /**
     * 根据名称查询
     *
     * @param adminName
     * @return
     */
    @Override
    public Admin findByAdminName(String adminName) throws SQLException {

        QueryRunner runner = new QueryRunner(JdbcUtil.getDataSource());

        String sql = "SELECT `admin_id` adminId,`admin_name` adminName,`password`,`status`,`phone`,`email`,`role`,`admin_create_time` adminCreateTime,`admin_update_time` adminUpdateTime FROM `t_admin` WHERE `admin_name` = ?";
        return runner.query(sql, new BeanHandler<>(Admin.class), adminName);
    }
}
